#include "voda.h"
#include "runtime.h"

namespace voda
{
	/**
	* \brief	JSContextCallback
	*/
	JSBool runtime::JSContextCallback (JSContext *cx, unsigned contextOp)
	{
		return JS_TRUE;
	}

	/**
	* \brief	construction
	*/
	runtime::runtime (uint32_t const runtime_size /* = traits::runtime_size */)
		: rt_ (JS_NewRuntime (runtime_size, JS_NO_HELPER_THREADS))
	{
		JS_ClearRuntimeThread (rt_);
		JSAutoSetRuntimeThread const autort (rt_);
		JS_SetGCParameter (rt_, JSGC_MODE, JSGC_MODE_INCREMENTAL);
		JS_SetContextCallback (rt_, runtime::JSContextCallback);
		JS_SetRuntimePrivate (rt_, this);
	}

	/**
	* \brief	destruction
	*/
	runtime::~runtime () throw ()
	{
		JS_SetRuntimeThread (rt_);
		JS_SetRuntimePrivate (rt_, NULL);
		JS_DestroyRuntime (rt_);
	}

}// namespace voda
